package com.dinghui.ebookbag;

import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import androidx.multidex.MultiDex;

import com.dinghui.ebookbag.enity.User;

public class EBookBagApplication extends Application {

    private static Context mContext;
    private static Handler handler;

    //private User loginUser = new User();//当前的登录用户

    private static AlertDialog myLoadingDialog;//做一个全局dialog baseActivity中已初始化

    @Override
    public void onCreate() {
        mContext = getApplicationContext();
        if (handler == null) {
            handler = new Handler(Looper.getMainLooper());
        }
        super.onCreate();
        MultiDex.install(this);
    }

    //dialog
    public AlertDialog getMyLoadingDialog() {
        return myLoadingDialog;
    }

    public void setMyLoadingDialog(AlertDialog myLoadingDialog) {
        this.myLoadingDialog = myLoadingDialog;
    }

    public static Boolean showLoadingDialog() {//显示dialog 默认20s后自动隐藏
        if (myLoadingDialog == null) {
            return false;
        }
        myLoadingDialog.show();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                myLoadingDialog.dismiss();
            }
        }, 20000);
        return true;
    }

    public static Boolean hideLoadingDialog() {//隐藏dialog
        if (myLoadingDialog == null) {
            return false;
        }
        myLoadingDialog.dismiss();
        return true;
    }


   /* public User getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(User user) {
        this.loginUser = user;
    }*/

    public static Context getmContext() {
        return mContext;
    }
}
